// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    slideshow:[],
    cateData:[],
    floorData:[]
  },
  // 小程序生命周期
  onLoad(){
    this.getslideshow()
    this.getCataData()
    this.getfloor()
  },
  onShow(){
     // 添加角标
     let arr=wx.getStorageSync('shopcart')
     let num=0
     arr.forEach(item=>{
      num+=item.num
     })
     wx.setTabBarBadge({
      index: 2,
      text: num+''
    })
  },
  
  // 轮播图
  getslideshow(){
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata',
      success:res=>{
        // console.log(res);
        this.setData({
          slideshow:res.data.message
        })
      },
      complete:com=>{
        wx.hideLoading({
          success: (res) => {},
        })
      }
    })
  },
  // 请求导航
  getCataData(){
    wx.request({
      url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/catitems',
      success:res=>{
        // console.log(res);
        this.setData({
          cateData:res.data.message
        })
      }
    })
  },
  // 楼层
  getfloor(){
    wx.request({
      url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/floordata',
      success:res=>{
        // console.log(res);
        this.setData({
          floorData:res.data.message
        })
      }
    })
  }
  
})
